package com.micro.db.dao;

import com.micro.model.DiskUser;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;


public interface DiskUserDao extends JpaRepository<DiskUser, String>,JpaSpecificationExecutor<DiskUser> {

    @Query("select t from DiskUser t where t.state = 1 and t.username=?1 ")
    public DiskUser findUserByUsername(String userName);

    @Query("select t from DiskUser t where t.state = 1 and t.username=?1 and t.password=?2 ")
    public DiskUser findUserByUsernameAndPwd(String userName,String password);

    @Modifying
    @Query("update DiskUser  set password = ?2 where username = ?1")
    public void updateUserPwd(String userName,String password);

    @Modifying
    @Query("update DiskUser  set password = ?2 where id = ?1")
    public void updateUserPwdById(String userId,String password);

    @Modifying
    @Query("update DiskUser  set state = 0 where id = ?1")
    public void logicDeleleUser(String userId);

    @Modifying
    @Query("update DiskUser set nickname = ?2 ,telephone = ?3  where id = ?1")
    public void updateUserPartInfo(String userId,String nickname,String telephone);
}
